using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;

namespace org.synthful.Win32
{
    public class RegistryHierarchy
    {
        public RegistryHierarchy(RegistryKey regkey, string regpath)
        {
            RegistryKey subkey = regkey.OpenSubKey(regpath);
        }

        static public RegistryNode navRegKey(RegistryKey regkey)
        {
            RegistryNode regnode = new RegistryNode();

            string[] valuenames = regkey.GetValueNames();
            if (valuenames.Length > 0)
            {
                regnode.Values = new Dictionary<string, RegistryValue>();

                foreach (string name in valuenames)
                {
                    RegistryValue regvalue = new RegistryValue();
                    regnode.Values.Add(name, regvalue);

                    regvalue.Value = regkey.GetValue(name);
                    regvalue.Kind = regkey.GetValueKind(name);
                }
            }

            string[] keynames = regkey.GetSubKeyNames();
            if (keynames.Length > 0)
            {
                regnode.SubKeys = new RegistryKey[keynames.Length];

                for (int i = 0; i < keynames.Length; i++ )
                {
                    RegistryKey subkey = regkey.OpenSubKey(keynames[i]);
                    navRegKey(subkey);
                }
            }
            return regnode;
        }
    }

    public struct RegistryNode
    {
        public RegistryKey Key;
        public RegistryKey[] SubKeys;
        public Dictionary<string, RegistryValue> Values;
    }

    public struct RegistryValue
    {
        public Object Value;
        public RegistryValueKind Kind;
    }
}
